package top.likeqc.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.likeqc.common.lang.Result;
import top.likeqc.dto.PaperDTO;
import top.likeqc.service.IAnswerService;
import top.likeqc.service.IPaperService;
import top.likeqc.service.IQuestionService;
import top.likeqc.vo.PaperAndQuestionVO;
import top.likeqc.vo.PaperVO;

import java.util.List;

/**
 * <p>
 * 问卷 前端控制器
 * </p>
 *
 * @author likeqc
 * @since 2022-04-16
 */
@RestController
@RequestMapping("/paper")
public class PaperController extends BaseController {

    @Autowired
    IPaperService paperService;

    @Autowired
    IQuestionService questionService;

    @Autowired
    IAnswerService answerService;

    @GetMapping()
    public Result page(Long courseId) {
        Page<PaperVO> page = paperService.listByCourseId(getPage(), courseId);

        return Result.success(page);
    }

    /**
     * 获取问卷和问题
     * @param paperId
     * @return
     */
    @GetMapping("/{paperId}")
    public Result getPaperAndQuestion(@PathVariable Long paperId) throws Exception {

        PaperAndQuestionVO paperAndQuestionVO = paperService.getPaperAndQuestion(paperId);

        return Result.success(paperAndQuestionVO);
    }

/*    @GetMapping("/student/{status}")
    public Result getCurPaperAndQuestion(@PathVariable Integer status) throws Exception {

        Page<PaperVO> page = paperService.getCurPaperAndQuestion(getPage(), status);
        // PaperAndQuestionVO paperAndQuestionVO = null;
        return Result.success(page);
    }*/

    @GetMapping("/student/todo")
    public Result getTodoPaper() throws Exception {

        Page<PaperVO> page = paperService.getTodoPaper(getPage());
        // PaperAndQuestionVO paperAndQuestionVO = null;
        return Result.success(page);
    }

    @GetMapping("/student/history")
    public Result getHistoryPaper() throws Exception {

        Page<PaperVO> page = paperService.getHistoryPaper(getPage());
        // PaperAndQuestionVO paperAndQuestionVO = null;
        return Result.success(page);
    }

    @GetMapping("/student/future")
    public Result getFuturePaper() throws Exception {

        Page<PaperVO> page = paperService.getFuturePaper(getPage());
        // PaperAndQuestionVO paperAndQuestionVO = null;
        return Result.success(page);
    }

    @PostMapping()
    public Result add(@RequestBody PaperDTO paperDTO) {

        boolean b = paperService.addPaperAndQuestion(paperDTO);

        return Result.success();
    }

    @DeleteMapping()
    public Result delete(@RequestBody List<Long> paperIds) {
        paperService.deleteByCourseId(paperIds);
        return Result.success();
    }

}
